package com.ruoyi.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.demo.domain.vo.inviteVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface inviteUserMapper extends BaseMapper<inviteVo> {
    @Select("select inviter_id,invite_time,meet_id,invite_code,user_name,invite.`status` as `status` from sys_user,invite where " +
            "user_id in (SELECT inviter_id FROM `invite` where invitee_id=#{inviteeId}) and sys_user." +
            "user_id=invite.inviter_id and invite.invitee_id=#{inviteeId}")
    List<inviteVo> getInviteByInviteeId(int inviteeId);
    @Select("SELECT " +
            "sys_user.user_name AS userName, " +
            "invite.invite_time AS inviteTime, " +
            "sys_dept.dept_name AS deptName, " +
            "meet.theme AS theme, " +
            "meet.meet_content AS meetContent, " +
            "meet.start_time AS startTime, " +
            "meet.end_time AS endTime, " +
            "room.room_address AS roomAddress " +
            "FROM meet, sys_user, sys_dept, room, invite " +
            "WHERE meet.meet_id = #{meetId} " +
            "AND meet.user_id = #{inviterId} " +
            "AND sys_user.user_id = meet.user_id " +
            "AND sys_user.dept_id = sys_dept.dept_id " +
            "AND room.room_id = meet.room_id " +
            "AND invite.inviter_id = #{inviterId} " +
            "AND invite.meet_id = #{meetId} "+
            "and invitee_id=#{userId}")
    inviteVo getInviteByInviterIdAndMeetId(@Param("inviterId") int inviterId, @Param("meetId") int meetId, @Param("userId") Long userId);
    @Update("UPDATE invite SET status = 1 WHERE meet_id = #{meetId} AND invitee_id = #{inviteeId}")
    int updateInviteStatus(@Param("inviteeId") int inviteeId, @Param("meetId") int meetId);
    @Select("SELECT " +
            "    invite.inviter_id AS inviterId, " +
            "    invite.invite_time AS inviteTime, " +
            "    invite.meet_id AS meetId, " +
            "    invite.invite_code AS inviteCode, " +
            "    sys_user.user_name AS userName, " +
            "    invite.`status` AS status " +
            "FROM " +
            "    invite " +
            "JOIN " +
            "    sys_user ON invite.inviter_id = sys_user.user_id " +
            "WHERE " +
            "    (invite.invite_code LIKE CONCAT('%', #{item}, '%') " +
            "    OR sys_user.user_name LIKE CONCAT('%', #{item}, '%')) " +
            "    AND invite.invitee_id = #{userId}")
    List<inviteVo> getInviteBySearch(@Param("item") String item, @Param("userId") Long userId);
    @Insert("INSERT INTO meet_user (user_id, meet_id,is_attented)" +
            " VALUES (#{userId}, #{meetId},1);")
    int insertMeetUser(@Param("userId") int userId, @Param("meetId") int meetId);
}
